package com.qdl.rym.base;

import com.qdl.rym.util.RequestUtil;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Description: BaseController
 * @Author: ChenXueLi
 * @Date: 2018-11-10 12:52
 */
@RestController
public class BaseController {

    /**
     * request对象
     */
    protected HttpServletRequest request;
    /**
     * response对象
     */
    protected HttpServletResponse response;
    /**
     * session对象
     */
    protected HttpSession session;

    /**
     * 返回对象
     */
    protected ResultModel resultModel;

    /**
     * 基础Http参数设置与绑定
     * @param request
     * @param response
     * @throws Exception
     */
    @InitBinder
    public void initHttpParams(HttpServletRequest request, HttpServletResponse response) throws Exception{
        this.request = request;
        this.response = response;
        this.session = this.request.getSession();
        this.resultModel = new ResultModel();
        String ip = RequestUtil.getInstance().getIpAddress(this.request);
        this.resultModel.setIp(ip);
    }

//    /**
//     * 绑定参数前缀
//     * @param binder
//     */
//    @InitBinder("requestModel")
//    public void initPrefixParams(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("requestModel.");
//    }

}
